import {
    navListLevel1,
    navListLevel2,
    NavLevel1Type,
    NavLevel2Type,
} from '@/database/channel'
import {
    channelDetail,
    channelDetailType as _channelDetailType
} from '@/database/channelDetail'

// 导航列表
export type NavListLevel1Type = Array<
    NavLevel1Type & {
        children: Array<NavLevel2Type>
    }
>
// 新闻详情
export type channelDetailType = _channelDetailType

export default defineWrappedResponseHandler((event)=>{
    return listenRequest(event, {
        /**
         * 获取导航列表
         */
        'list': (data:Record<string,any>) :NavListLevel1Type =>{
            const id = data.params.id
            const res = navListLevel1.map(item=>({
                ...item,
                children: navListLevel2.filter(child => child.pid === item.id)
            }))
            return (id ? res.filter(item => item.id == id) : res)
        },
        /**
         * 获取详情
         */
        'detail': (data:Record<string,any>)=>{
            const id = data.params.id
            return channelDetail.find(item=>item.id == id)
        },
    })
})